package so.shanku.essential.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import net.tsz.afinal.json.JsonMap;
import so.shanku.essential.R;

import java.util.Map;
import java.util.List;


/**
 * Created by xiaozhen on 2016/3/24.
 * 我的预约数据适配
 */
public class MyAppointmentAdapter extends MyBaseAdapter{
	//Button监听
	ItemCompontClickListener itemCompontClickListener;

	public void setItemCompontClickListener(ItemCompontClickListener itemCompontClickListener) {
		this.itemCompontClickListener = itemCompontClickListener;
	}

	public MyAppointmentAdapter(Context context){
		super(context);
	}

	public MyAppointmentAdapter(Context context, List<? extends Map<String,?>> datas) {
		super(context, datas);
	}

	@Override
	public int getCount() {
		return 5;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		MyAppointmentAdapterViewHolder myAppointmentAdapterViewHolder;
		if (view == null) {
			myAppointmentAdapterViewHolder = new MyAppointmentAdapterViewHolder();
			view = layoutInflater.inflate(R.layout.item_myappointment, null);
			ViewUtils.inject(myAppointmentAdapterViewHolder, view);
			view.setTag(myAppointmentAdapterViewHolder);
		} else {
			myAppointmentAdapterViewHolder = (MyAppointmentAdapterViewHolder) view.getTag();
		}
		setItemTag(i,myAppointmentAdapterViewHolder);
		//bindData(i, myAppointmentAdapterViewHolder);

		return view;
	}

	/**
	 * 往控件里加值
	 * @param i
	 * @param myAppointmentAdapterViewHolder
	 */
	private void bindData(int i, MyAppointmentAdapterViewHolder myAppointmentAdapterViewHolder) {
		JsonMap jsonMap= (JsonMap) datas.get(i);
		myAppointmentAdapterViewHolder.appointment_Name_tv.setText(jsonMap.getStringNoNull("appointmentName"));
		//图片
//		myAppointmentAdapterViewHolder.appointment_civ.IMA(jsonMap.get);
		myAppointmentAdapterViewHolder.appointment_number_detail_tv.setText(jsonMap.getStringNoNull("appointmentNumberDetail"));
		myAppointmentAdapterViewHolder.appointment_date_detail_tv.setText(jsonMap.getStringNoNull("appointmentDateDetail"));
		myAppointmentAdapterViewHolder.appointment_time_detail_tv.setText(jsonMap.getStringNoNull("appointmentTimeDetail"));
		myAppointmentAdapterViewHolder.appointment_pepole_count_detail_tv.setText(jsonMap.getStringNoNull("appointmentPepoleCountDetail"));
		myAppointmentAdapterViewHolder.appointment_address_detail_tv.setText(jsonMap.getStringNoNull("appointmentAddressDetail"));
	}

	/**
	 * 可以点击控件的位置
	 * @param i
	 * @param myAppointmentAdapterViewHolder
	 */
	private void setItemTag(int i, MyAppointmentAdapterViewHolder myAppointmentAdapterViewHolder) {
		myAppointmentAdapterViewHolder.appointment_civ.setTag(i);
		myAppointmentAdapterViewHolder.appointment_see_detail_tv.setTag(i) ;
		myAppointmentAdapterViewHolder.update_appointment_tv.setTag(i) ;

	}

	/**
	 * 所有涉及到的控件
	 */
	public class  MyAppointmentAdapterViewHolder {

		@ViewInject(R.id.appointment_Name_tv)
		private TextView appointment_Name_tv;

		@ViewInject(R.id.appointment_civ)
		private ImageView appointment_civ;

		@ViewInject(R.id.appointment_see_detail_tv)
		private TextView appointment_see_detail_tv;

		@ViewInject(R.id.update_appointment_tv)
		private TextView update_appointment_tv;

		@ViewInject(R.id.appointment_number_detail_tv)
		private TextView appointment_number_detail_tv;

		@ViewInject(R.id.appointment_date_detail_tv)
		private TextView appointment_date_detail_tv;

		@ViewInject(R.id.appointment_time_detail_tv)
		private TextView appointment_time_detail_tv;

		@ViewInject(R.id.appointment_pepole_count_detail_tv)
		private TextView appointment_pepole_count_detail_tv;

		@ViewInject(R.id.appointment_address_detail_tv)
		private TextView appointment_address_detail_tv;

	}

	public interface ItemCompontClickListener {
		/**
		 * @param position         根位置
		 * @param itemType 类别
		 */
		void onItemCompontClickListener(int position, int itemType);
	}
}
